package com.gxar.quick.ar.server.base.model.protocol.client.wechat_mp;

import com.gxar.quick.ar.server.base.common.enums.protocol.ArDisplayModeEnum;
import com.gxar.quick.ar.server.base.model.protocol.ArVector3;
import com.gxar.quick.ar.server.base.model.protocol.common.CommonArImageIdentifyModel;
import com.gxar.quick.ar.server.base.model.protocol.common.CommonArProtocol;
import lombok.Data;

/**
 * 微信小程序 - AR识别图信息
 *
 * @author zxh
 * @version 1.0
 * @created 2024/01/02.
 */
@Data
public class WechatMpClientArIdentifyModel {

    /**
     * 版本信息
     */
    private String version;

    /**
     * 作品编号
     */
    private String workId;

    /**
     * 资源链接
     */
    private String linkUrl;

    /**
     * 识别图宽度
     */
    private Double width;

    /**
     * 识别图高度
     */
    private Double height;

    /**
     * 是否展示识别图
     */
    private Boolean showIdentify;

    /**
     * 缩放
     */
    private String scale;

    /**
     * 位置
     */
    private String position;

    /**
     * 旋转，欧拉角，XYZ
     */
    private String rotation;

    /**
     * 是否存在水印
     */
    private Integer waterMark;

    public static WechatMpClientArIdentifyModel from(CommonArProtocol inputProtocol) {
        CommonArImageIdentifyModel inputModel = (CommonArImageIdentifyModel) inputProtocol.getIdentifyModel();

        WechatMpClientArIdentifyModel outputModel = new WechatMpClientArIdentifyModel();
        outputModel.setVersion(inputProtocol.getVersion());
        outputModel.setWorkId(inputProtocol.getWorkId());
        outputModel.setLinkUrl(inputModel.getEncodeLinkUrl());
        outputModel.setWidth(inputModel.getWorldSize().getWidth());
        outputModel.setHeight(inputModel.getWorldSize().getHeight());
        outputModel.setShowIdentify(inputModel.getShowIdentify());
        outputModel.setRotation(inputModel.getRotation().toString());
        outputModel.setWaterMark(inputProtocol.getWaterMark());

        if (ArDisplayModeEnum.PLANE.equals(inputProtocol.getDisplayMode())) {
            // 投放模式, 缩小展示
            ArVector3 planeModeScale = WechatMpClientArProtocol.getSizeOnPlaneMode(inputModel.getScale());
            outputModel.setScale(planeModeScale.toString());

            ArVector3 planeModePosition = WechatMpClientArProtocol.getSizeOnPlaneMode(inputModel.getPosition());
            outputModel.setPosition(planeModePosition.toString());
        } else {
            // 其它模式，正常展示
            outputModel.setScale(inputModel.getScale().toString());
            outputModel.setPosition(inputModel.getPosition().toString());
        }

        return outputModel;
    }
}
